package cn.com.dcsgo.controller;

import cn.com.dcsgo.domain.ShopDetail;
import cn.com.dcsgo.dto.ShopInfoDTO;
import cn.com.dcsgo.service.ShopDetailService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 店铺远程调用相关接口
 *
 * @author Dcsgo
 * @since 2025/11/15 9:49
 */
@Tag(name = "店铺RPC相关接口")
@RestController
@RequestMapping("rpc/shop")
public class ShopRPCController {
    @Resource
    private ShopDetailService shopDetailService;

    @GetMapping("ids/id-and-shop-name")
    @Operation(summary = "获取店铺ID及其名称", description = "通过店铺ID列表获取")
    public List<ShopInfoDTO> getShopInfoDTOList(@RequestParam("shopIds") Set<Long> shopIds) {
        List<ShopDetail> shopDetailList = shopDetailService.list(
                new LambdaQueryWrapper<ShopDetail>()
                        .select(ShopDetail::getShopId, ShopDetail::getShopName)
                        .in(ShopDetail::getShopId, shopIds)
        );
        ArrayList<ShopInfoDTO> shopInfoDTOArrayList = new ArrayList<>(shopDetailList.size());
        shopDetailList.forEach(shopDetail -> {
            ShopInfoDTO shopInfoDTO = new ShopInfoDTO();
            shopInfoDTO.setShopId(shopDetail.getShopId());
            shopInfoDTO.setShopName(shopDetail.getShopName());
            shopInfoDTOArrayList.add(shopInfoDTO);
        });
        return shopInfoDTOArrayList;
    }
}
